---

title: Spliting data


keywords: fastai
sidebar: home_sidebar

summary: "Functions required to perform cross-validation and transform unique time series sequence into multiple samples ready to be used by a time series model."
description: "Functions required to perform cross-validation and transform unique time series sequence into multiple samples ready to be used by a time series model."
nb_path: "nbs/010_data.validation.ipynb"
---
<!--

#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: nbs/010_data.validation.ipynb
# command to build the docs after a change: nbdev_build_docs

-->

<div class="container" id="notebook-container">
        
    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="check_overlap" class="doc_header"><code>check_overlap</code><a href="https://github.com/timeseriesAI/tsai/tree/main/tsai/data/validation.py#L16" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>check_overlap</code>(<strong><code>a</code></strong>, <strong><code>b</code></strong>, <strong><code>c</code></strong>=<em><code>None</code></em>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="check_splits_overlap" class="doc_header"><code>check_splits_overlap</code><a href="https://github.com/timeseriesAI/tsai/tree/main/tsai/data/validation.py#L33" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>check_splits_overlap</code>(<strong><code>splits</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="leakage_finder" class="doc_header"><code>leakage_finder</code><a href="https://github.com/timeseriesAI/tsai/tree/main/tsai/data/validation.py#L36" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>leakage_finder</code>(<strong>*<code>splits</code></strong>, <strong><code>verbose</code></strong>=<em><code>True</code></em>)</p>
</blockquote>
<p>You can pass splits as a tuple, or train, valid, ...</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="balance_idx" class="doc_header"><code>balance_idx</code><a href="https://github.com/timeseriesAI/tsai/tree/main/tsai/data/validation.py#L49" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>balance_idx</code>(<strong><code>o</code></strong>, <strong><code>shuffle</code></strong>=<em><code>False</code></em>, <strong><code>random_state</code></strong>=<em><code>None</code></em>, <strong><code>verbose</code></strong>=<em><code>False</code></em>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">check_overlap</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">9</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">check_overlap</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="p">[</span><span class="mi">9</span><span class="p">])</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="mi">30</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">check_overlap</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">),</span> <span class="kc">False</span><span class="p">)</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">30</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">check_overlap</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">),</span> <span class="p">([],</span> <span class="p">[],</span> <span class="p">[</span><span class="mi">10</span><span class="p">,</span> <span class="mi">11</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="mi">13</span><span class="p">,</span> <span class="mi">14</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="mi">16</span><span class="p">,</span> <span class="mi">17</span><span class="p">,</span> <span class="mi">18</span><span class="p">,</span> <span class="mi">19</span><span class="p">]))</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">l</span> <span class="o">=</span> <span class="n">L</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">concat</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">5</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="mi">10</span><span class="p">))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">)))</span>
<span class="n">balanced_idx</span> <span class="o">=</span> <span class="n">balance_idx</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">l</span><span class="p">[</span><span class="n">balanced_idx</span><span class="p">]),</span> <span class="mf">0.5</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">balanced_idx</span><span class="p">,</span> <span class="n">L</span><span class="p">),</span> <span class="kc">True</span><span class="p">)</span>

<span class="n">l</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">concat</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">5</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="mi">10</span><span class="p">))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">))</span>
<span class="n">balanced_idx</span> <span class="o">=</span> <span class="n">balance_idx</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">L</span><span class="p">(</span><span class="n">l</span><span class="p">)[</span><span class="n">balanced_idx</span><span class="p">]),</span> <span class="mf">0.5</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">balanced_idx</span><span class="p">,</span> <span class="n">L</span><span class="p">),</span> <span class="kc">True</span><span class="p">)</span>

<span class="n">a</span> <span class="o">=</span> <span class="n">concat</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">5</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="mi">10</span><span class="p">))</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>
<span class="n">balanced_idx</span> <span class="o">=</span> <span class="n">balance_idx</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">balanced_idx</span><span class="p">]),</span> <span class="mf">0.5</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">balanced_idx</span><span class="p">,</span> <span class="n">L</span><span class="p">),</span> <span class="kc">True</span><span class="p">)</span>

<span class="n">t</span> <span class="o">=</span> <span class="n">concat</span><span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">5</span><span class="p">),</span> <span class="n">torch</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="mi">10</span><span class="p">))</span>
<span class="n">balanced_idx</span> <span class="o">=</span> <span class="n">balance_idx</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="n">balanced_idx</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">(),</span> <span class="mf">0.5</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">balanced_idx</span><span class="p">,</span> <span class="n">L</span><span class="p">),</span> <span class="kc">True</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">100_000</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">100_000</span><span class="p">,</span> <span class="mi">200_000</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">soft_labels</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">filter_pseudolabels</span> <span class="o">=</span> <span class="mf">.5</span>
<span class="n">balanced_pseudolabels</span> <span class="o">=</span> <span class="kc">True</span>


<span class="n">pseudolabels</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span>
<span class="n">pseudolabels</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">softmax</span><span class="p">(</span><span class="n">pseudolabels</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="k">if</span> <span class="n">soft_labels</span> <span class="k">else</span> <span class="n">torch</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">pseudolabels</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="n">hpl</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">pseudolabels</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="k">if</span> <span class="n">soft_labels</span> <span class="k">else</span> <span class="n">pseudolabels</span>

<span class="k">if</span> <span class="n">filter_pseudolabels</span> <span class="ow">and</span> <span class="n">pseudolabels</span><span class="o">.</span><span class="n">ndim</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span> 
    <span class="n">error</span> <span class="o">=</span> <span class="mi">1</span> <span class="o">-</span> <span class="n">pseudolabels</span><span class="o">.</span><span class="n">max</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">values</span>
    <span class="n">filt_pl_idx</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">error</span><span class="p">))[</span><span class="n">error</span> <span class="o">&lt;</span> <span class="n">filter_pseudolabels</span><span class="p">]</span>
    <span class="n">filt_pl</span> <span class="o">=</span> <span class="n">pseudolabels</span><span class="p">[</span><span class="n">error</span> <span class="o">&lt;</span> <span class="n">filter_pseudolabels</span><span class="p">]</span>
    <span class="k">assert</span> <span class="nb">len</span><span class="p">(</span><span class="n">filt_pl</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;no filtered pseudolabels&#39;</span>
    <span class="n">filt_hpl</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">argmax</span><span class="p">(</span><span class="n">filt_pl</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span> 
    <span class="n">filt_pl_idx</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">pseudolabels</span><span class="p">))</span>
    <span class="n">filt_pl</span> <span class="o">=</span> <span class="n">filt_hpl</span> <span class="o">=</span> <span class="n">pseudolabels</span>
<span class="n">pl_split</span> <span class="o">=</span> <span class="n">filt_pl_idx</span><span class="p">[</span><span class="n">balance_idx</span><span class="p">(</span><span class="n">filt_hpl</span><span class="p">)]</span> <span class="k">if</span> <span class="n">balanced_pseudolabels</span> <span class="k">else</span> <span class="n">filt_pl_idx</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">hpl</span><span class="p">[</span><span class="n">pl_split</span><span class="p">]</span><span class="o">.</span><span class="n">float</span><span class="p">()</span><span class="o">.</span><span class="n">mean</span><span class="p">(),</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">unique</span><span class="p">(</span><span class="n">hpl</span><span class="p">)))</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="TrainValidTestSplitter" class="doc_header"><code>TrainValidTestSplitter</code><a href="https://github.com/timeseriesAI/tsai/tree/main/tsai/data/validation.py#L59" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>TrainValidTestSplitter</code>(<strong><code>n_splits</code></strong>:<code>int</code>=<em><code>1</code></em>, <strong><code>valid_size</code></strong>:<code>Union</code>[<code>float</code>, <code>int</code>]=<em><code>0.2</code></em>, <strong><code>test_size</code></strong>:<code>Union</code>[<code>float</code>, <code>int</code>]=<em><code>0.0</code></em>, <strong><code>train_only</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>stratify</code></strong>:<code>bool</code>=<em><code>True</code></em>, <strong><code>balance</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>shuffle</code></strong>:<code>bool</code>=<em><code>True</code></em>, <strong><code>random_state</code></strong>:<code>Union</code>[<code>NoneType</code>, <code>int</code>]=<em><code>None</code></em>, <strong><code>verbose</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong>**<code>kwargs</code></strong>)</p>
</blockquote>
<p>Split <code>items</code> into random train, valid (and test optional) subsets.</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="plot_splits" class="doc_header"><code>plot_splits</code><a href="https://github.com/timeseriesAI/tsai/tree/main/tsai/data/validation.py#L161" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>plot_splits</code>(<strong><code>splits</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="get_splits" class="doc_header"><code>get_splits</code><a href="https://github.com/timeseriesAI/tsai/tree/main/tsai/data/validation.py#L202" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>get_splits</code>(<strong><code>o</code></strong>, <strong><code>n_splits</code></strong>:<code>int</code>=<em><code>1</code></em>, <strong><code>valid_size</code></strong>:<code>float</code>=<em><code>0.2</code></em>, <strong><code>test_size</code></strong>:<code>float</code>=<em><code>0.0</code></em>, <strong><code>train_only</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>train_size</code></strong>:<code>Union</code>[<code>NoneType</code>, <code>float</code>, <code>int</code>]=<em><code>None</code></em>, <strong><code>balance</code></strong>:<code>bool</code>=<em><code>False</code></em>, <strong><code>shuffle</code></strong>:<code>bool</code>=<em><code>True</code></em>, <strong><code>stratify</code></strong>:<code>bool</code>=<em><code>True</code></em>, <strong><code>check_splits</code></strong>:<code>bool</code>=<em><code>True</code></em>, <strong><code>random_state</code></strong>:<code>Union</code>[<code>NoneType</code>, <code>int</code>]=<em><code>None</code></em>, <strong><code>show_plot</code></strong>:<code>bool</code>=<em><code>True</code></em>, <strong><code>verbose</code></strong>:<code>bool</code>=<em><code>False</code></em>)</p>
</blockquote>
<p>Arguments:
o            : object to which splits will be applied, usually target.
n_splits     : number of folds. Must be an int &gt;= 1.
valid_size   : size of validation set. Only used if n_splits = 1. If n_splits &gt; 1 valid_size = (1. - test_size) / n_splits.
test_size    : size of test set. Default = 0.
train_only   : if True valid set == train set. This may be useful for debugging purposes.
train_size   : size of the train set used. Default = None (the remainder after assigning both valid and test).
                Useful for to get learning curves with different train sizes or get a small batch to debug a neural net.
balance      : whether to balance data so that train always contain the same number of items per class.
shuffle      : whether to shuffle data before splitting into batches. Note that the samples within each split will be shuffle.
stratify     : whether to create folds preserving the percentage of samples for each class.
check_splits : whether to perform leakage and completion checks.
random_state : when shuffle is True, random_state affects the ordering of the indices. Pass an int for reproducible output.
show_plot    : plot the split distribution</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">n_splits</span>                <span class="o">=</span> <span class="mi">5</span>
<span class="n">valid_size</span>              <span class="o">=</span> <span class="mf">0.2</span>
<span class="n">test_size</span>               <span class="o">=</span> <span class="mf">0.2</span>
<span class="n">train_only</span>              <span class="o">=</span> <span class="kc">False</span>  <span class="c1"># set to True for debugging (valid = train)</span>
<span class="n">train_size</span>              <span class="o">=</span> <span class="mi">5000</span>
<span class="n">stratify</span>                <span class="o">=</span> <span class="kc">True</span>
<span class="n">balance</span>                 <span class="o">=</span> <span class="kc">True</span>
<span class="n">shuffle</span>                 <span class="o">=</span> <span class="kc">True</span>
<span class="n">predefined_splits</span>       <span class="o">=</span> <span class="kc">None</span>
<span class="n">show_plot</span>               <span class="o">=</span> <span class="kc">True</span> 


<span class="n">check_splits</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">random_state</span> <span class="o">=</span> <span class="mi">23</span>

<span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">10000</span><span class="p">)</span> <span class="o">+</span> <span class="mi">100</span>

<span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">n_splits</span><span class="o">=</span><span class="n">n_splits</span><span class="p">,</span> <span class="n">valid_size</span><span class="o">=</span><span class="n">valid_size</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="n">test_size</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="n">shuffle</span><span class="p">,</span> <span class="n">balance</span><span class="o">=</span><span class="n">balance</span><span class="p">,</span> <span class="n">stratify</span><span class="o">=</span><span class="n">stratify</span><span class="p">,</span>
                    <span class="n">train_only</span><span class="o">=</span><span class="n">train_only</span><span class="p">,</span> <span class="n">train_size</span><span class="o">=</span><span class="n">train_size</span><span class="p">,</span> <span class="n">check_splits</span><span class="o">=</span><span class="n">check_splits</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="n">random_state</span><span class="p">,</span> <span class="n">show_plot</span><span class="o">=</span><span class="n">show_plot</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">splits</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>(((#5000) [6604,3593,8005,3280,3451,7846,7683,8649,2488,2368...],
  (#1600) [5724,1035,6708,55,3895,4572,7917,3987,1512,811...],
  (#2000) [3484,9724,1032,7164,6934,2149,1010,2235,1179,5839...]),
 ((#5000) [3086,3315,6721,7877,9760,3187,2010,1867,120,3832...],
  (#1600) [8240,4340,7580,4992,9464,3075,6049,2176,8325,8951...],
  (#2000) [3484,9724,1032,7164,6934,2149,1010,2235,1179,5839...]),
 ((#5000) [9715,259,340,8024,1834,4909,9869,8438,6025,8811...],
  (#1600) [8361,6081,9440,5951,9876,9020,6283,5545,1074,5338...],
  (#2000) [3484,9724,1032,7164,6934,2149,1010,2235,1179,5839...]),
 ((#5000) [3671,5261,4077,7380,8731,3912,5083,8868,1269,7901...],
  (#1600) [5111,684,1589,6581,7984,9961,5955,991,3392,2214...],
  (#2000) [3484,9724,1032,7164,6934,2149,1010,2235,1179,5839...]),
 ((#5000) [3858,8771,7805,6150,2978,2192,8660,8301,2458,5111...],
  (#1600) [3778,7824,8854,8872,7255,5827,5182,9501,1835,4511...],
  (#2000) [3484,9724,1032,7164,6934,2149,1010,2235,1179,5839...]))</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">train_size</span><span class="o">=</span><span class="mi">256</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span> <span class="o">+</span> <span class="mi">100</span>
<span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">train_size</span><span class="o">=</span><span class="n">train_size</span><span class="p">,</span> <span class="n">train_only</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">splits</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">splits</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splits</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="n">train_size</span><span class="p">)</span>
<span class="n">splits</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>valid == train
</pre>
</div>
</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>((#256) [935,502,884,723,796,339,996,579,638,15...],
 (#256) [935,502,884,723,796,339,996,579,638,15...])</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="TSSplitter" class="doc_header"><code>TSSplitter</code><a href="https://github.com/timeseriesAI/tsai/tree/main/tsai/data/validation.py#L268" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>TSSplitter</code>(<strong><code>valid_size</code></strong>:<code>Union</code>[<code>int</code>, <code>float</code>]=<em><code>0.2</code></em>, <strong><code>test_size</code></strong>:<code>Union</code>[<code>int</code>, <code>float</code>]=<em><code>0.0</code></em>, <strong><code>show_plot</code></strong>:<code>bool</code>=<em><code>True</code></em>)</p>
</blockquote>
<p>Create function that splits <code>items</code> between train/val with <code>valid_size</code> without shuffling data.</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">1000</span><span class="p">)</span> <span class="o">+</span> <span class="mi">100</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">TimeSplitter</span><span class="p">(</span><span class="n">valid_size</span><span class="o">=</span><span class="mf">0.2</span><span class="p">)(</span><span class="n">y</span><span class="p">)[</span><span class="mi">1</span><span class="p">],</span> <span class="n">L</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">800</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span><span class="o">.</span><span class="n">tolist</span><span class="p">()))</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">TimeSplitter</span><span class="p">(</span><span class="n">valid_size</span><span class="o">=</span><span class="mf">0.2</span><span class="p">)(</span><span class="n">y</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span> <span class="n">TimeSplitter</span><span class="p">(</span><span class="n">valid_size</span><span class="o">=</span><span class="mi">200</span><span class="p">)(</span><span class="n">y</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">TimeSplitter</span><span class="p">(</span><span class="n">valid_size</span><span class="o">=</span><span class="mf">0.2</span><span class="p">,</span> <span class="n">show_plot</span><span class="o">=</span><span class="kc">True</span><span class="p">)(</span><span class="n">y</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>((#800) [0,1,2,3,4,5,6,7,8,9...],
 (#200) [800,801,802,803,804,805,806,807,808,809...])</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">n_splits</span>                <span class="o">=</span> <span class="mi">5</span>
<span class="n">valid_size</span>              <span class="o">=</span> <span class="mf">0.2</span>  
<span class="n">test_size</span>               <span class="o">=</span> <span class="mi">0</span>
<span class="n">train_only</span>              <span class="o">=</span> <span class="kc">False</span>  <span class="c1"># set to True for debugging (valid = train)</span>
<span class="n">train_size</span>              <span class="o">=</span> <span class="kc">None</span>
<span class="n">stratify</span>                <span class="o">=</span> <span class="kc">True</span>
<span class="n">balance</span>                 <span class="o">=</span> <span class="kc">True</span>
<span class="n">shuffle</span>                 <span class="o">=</span> <span class="kc">True</span>
<span class="n">predefined_splits</span>       <span class="o">=</span> <span class="kc">None</span>
<span class="n">show_plot</span>               <span class="o">=</span> <span class="kc">True</span> 


<span class="n">check_splits</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">random_state</span> <span class="o">=</span> <span class="mi">23</span>

<span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">n_splits</span><span class="o">=</span><span class="n">n_splits</span><span class="p">,</span> <span class="n">valid_size</span><span class="o">=</span><span class="n">valid_size</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="n">test_size</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="n">shuffle</span><span class="p">,</span> <span class="n">balance</span><span class="o">=</span><span class="n">balance</span><span class="p">,</span> <span class="n">stratify</span><span class="o">=</span><span class="n">stratify</span><span class="p">,</span>
                    <span class="n">train_only</span><span class="o">=</span><span class="n">train_only</span><span class="p">,</span> <span class="n">train_size</span><span class="o">=</span><span class="n">train_size</span><span class="p">,</span> <span class="n">check_splits</span><span class="o">=</span><span class="n">check_splits</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="n">random_state</span><span class="p">,</span> <span class="n">show_plot</span><span class="o">=</span><span class="n">show_plot</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">split</span> <span class="o">=</span> <span class="n">splits</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="k">if</span> <span class="n">n_splits</span> <span class="o">==</span> <span class="mi">1</span> <span class="k">else</span> <span class="n">splits</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
<span class="n">y</span><span class="p">[</span><span class="n">split</span><span class="p">]</span><span class="o">.</span><span class="n">mean</span><span class="p">(),</span> <span class="n">split</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>stratify set to False as n_splits=5 cannot be greater than the min number of members in each class (1).
</pre>
</div>
</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>(601.11, (#800) [314,194,782,789,502,917,137,415,904,181...])</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">list</span><span class="p">([</span><span class="n">splits</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">splits</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">splits</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">splits</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="n">splits</span><span class="p">[</span><span class="mi">4</span><span class="p">]])</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>[((#800) [314,194,782,789,502,917,137,415,904,181...],
  (#200) [362,151,934,378,95,597,500,117,980,844...]),
 ((#800) [312,198,777,788,515,910,145,413,898,186...],
  (#200) [352,133,955,396,64,596,442,79,991,882...]),
 ((#800) [311,197,783,791,507,922,145,416,908,184...],
  (#200) [338,125,912,361,54,594,486,88,994,859...]),
 ((#800) [296,181,782,789,493,917,130,401,905,165...],
  (#200) [405,199,953,444,113,610,515,137,997,881...]),
 ((#800) [320,190,782,788,506,906,141,412,893,178...],
  (#200) [336,149,942,358,49,582,472,70,990,907...])]</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">n_splits</span> <span class="o">=</span> <span class="mi">5</span>
<span class="n">valid_size</span> <span class="o">=</span> <span class="mf">0.</span>
<span class="n">test_size</span> <span class="o">=</span> <span class="mf">0.</span>
<span class="n">shuffle</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">stratify</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">train_only</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">train_size</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">check_splits</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">random_state</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">show_plot</span> <span class="o">=</span> <span class="kc">True</span> 

<span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">n_splits</span><span class="o">=</span><span class="n">n_splits</span><span class="p">,</span> <span class="n">valid_size</span><span class="o">=</span><span class="n">valid_size</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="n">test_size</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="n">shuffle</span><span class="p">,</span> <span class="n">stratify</span><span class="o">=</span><span class="n">stratify</span><span class="p">,</span>
                    <span class="n">train_only</span><span class="o">=</span><span class="n">train_only</span><span class="p">,</span> <span class="n">train_size</span><span class="o">=</span><span class="n">train_size</span><span class="p">,</span> <span class="n">check_splits</span><span class="o">=</span><span class="n">check_splits</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="n">random_state</span><span class="p">,</span> <span class="n">show_plot</span><span class="o">=</span><span class="n">show_plot</span><span class="p">,</span> <span class="n">verbose</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">for</span> <span class="n">split</span> <span class="ow">in</span> <span class="n">splits</span><span class="p">:</span> 
    <span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">split</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">))</span>
    <span class="n">test_eq</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">split</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">)))</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">

<div class="output_subarea output_stream output_stdout output_text">
<pre>stratify set to False as n_splits=5 cannot be greater than the min number of members in each class (1).
valid == train
</pre>
</div>
</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">n_splits</span> <span class="o">=</span> <span class="mi">5</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span>

<span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">n_splits</span><span class="o">=</span><span class="n">n_splits</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">check_splits</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">((</span><span class="n">L</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="o">*</span><span class="n">splits</span><span class="p">))[</span><span class="mi">1</span><span class="p">])),</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">)))</span>

<span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">n_splits</span><span class="o">=</span><span class="n">n_splits</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">check_splits</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">concatenate</span><span class="p">((</span><span class="n">L</span><span class="p">(</span><span class="nb">zip</span><span class="p">(</span><span class="o">*</span><span class="n">splits</span><span class="p">))[</span><span class="mi">1</span><span class="p">]))),</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">)))</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">n_splits</span> <span class="o">=</span> <span class="mi">2</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span>

<span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">n_splits</span><span class="o">=</span><span class="n">n_splits</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mf">0.2</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">n_splits</span><span class="p">):</span> <span class="n">leakage_finder</span><span class="p">(</span><span class="o">*</span><span class="n">splits</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splits</span><span class="p">),</span> <span class="n">n_splits</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splits</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="mi">3</span><span class="p">)</span>
<span class="n">s</span> <span class="o">=</span> <span class="p">[]</span>
<span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">split</span><span class="p">)</span> <span class="k">for</span> <span class="n">split</span> <span class="ow">in</span> <span class="n">splits</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">s</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">)))</span>
<span class="n">s</span> <span class="o">=</span> <span class="p">[]</span>
<span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">split</span><span class="p">)</span> <span class="k">for</span> <span class="n">split</span> <span class="ow">in</span> <span class="n">splits</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">s</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">)))</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span>
<span class="n">splits1</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">valid_size</span><span class="o">=</span><span class="mf">.25</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">23</span><span class="p">,</span> <span class="n">stratify</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">splits2</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">valid_size</span><span class="o">=</span><span class="mf">.25</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">23</span><span class="p">,</span> <span class="n">stratify</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">splits3</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">valid_size</span><span class="o">=</span><span class="mf">.25</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stratify</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">splits4</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">valid_size</span><span class="o">=</span><span class="mf">.25</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stratify</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">splits1</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">splits2</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">test_ne</span><span class="p">(</span><span class="n">splits3</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">splits4</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">valid_size</span><span class="o">=</span><span class="mf">.25</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">23</span><span class="p">,</span> <span class="n">stratify</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splits</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">valid_size</span><span class="o">=</span><span class="mf">.25</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">23</span><span class="p">,</span> <span class="n">stratify</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splits</span><span class="p">),</span> <span class="mi">2</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">valid_size</span><span class="o">=</span><span class="mf">.25</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">23</span><span class="p">,</span> <span class="n">stratify</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splits</span><span class="p">),</span> <span class="mi">3</span><span class="p">)</span>
<span class="n">leakage_finder</span><span class="p">(</span><span class="o">*</span><span class="n">splits</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">splits</span> <span class="o">=</span> <span class="n">TrainValidTestSplitter</span><span class="p">(</span><span class="n">valid_size</span><span class="o">=</span><span class="mf">.25</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">23</span><span class="p">,</span> <span class="n">stratify</span><span class="o">=</span><span class="kc">True</span><span class="p">)(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">100</span><span class="p">))</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splits</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="mi">25</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splits</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="mi">20</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">o</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1000</span><span class="p">)</span>
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mf">.75</span><span class="p">,</span> <span class="mf">.5</span><span class="p">,</span> <span class="mf">.25</span><span class="p">,</span> <span class="mf">.125</span><span class="p">]:</span>
    <span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">train_size</span><span class="o">=</span><span class="n">p</span><span class="p">)</span>
    <span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splits</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="nb">len</span><span class="p">(</span><span class="n">o</span><span class="p">)</span> <span class="o">*</span> <span class="mf">.8</span> <span class="o">*</span> <span class="n">p</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="n">L</span><span class="p">([</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="mi">50</span> <span class="o">+</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mi">25</span> <span class="o">+</span> <span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="mi">15</span> <span class="o">+</span> <span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">*</span> <span class="mi">10</span><span class="p">)</span>
<span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">valid_size</span><span class="o">=</span><span class="mf">.2</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mf">.2</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">splits</span><span class="p">[</span><span class="mi">0</span><span class="p">]])</span><span class="o">==</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">splits</span><span class="p">[</span><span class="mi">1</span><span class="p">]])</span><span class="o">==</span><span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">y</span><span class="p">[</span><span class="n">splits</span><span class="p">[</span><span class="mi">2</span><span class="p">]]),</span> <span class="kc">True</span><span class="p">)</span>
<span class="n">splits</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>((#60) [56,0,83,35,86,31,57,84,58,63...],
 (#20) [23,47,5,71,11,67,18,65,82,30...],
 (#20) [72,1,46,37,60,20,22,53,38,66...])</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">y</span> <span class="o">=</span> <span class="n">L</span><span class="p">([</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="mi">50</span> <span class="o">+</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">*</span> <span class="mi">25</span> <span class="o">+</span> <span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">*</span> <span class="mi">15</span> <span class="o">+</span> <span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">*</span> <span class="mi">10</span><span class="p">)</span>
<span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">n_splits</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">valid_size</span><span class="o">=</span><span class="mf">.2</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mf">.2</span><span class="p">,</span> <span class="n">shuffle</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="c1"># test_eq(splits[0] + splits[1] + splits[2], np.arange(100))</span>
<span class="n">splits</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>((#60) [0,1,2,3,4,5,6,7,8,9...],
 (#20) [60,61,62,63,64,65,66,67,68,69...],
 (#20) [80,81,82,83,84,85,86,87,88,89...])</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">100</span><span class="p">),</span> <span class="n">valid_size</span><span class="o">=</span><span class="mf">0.213</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mi">17</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splits</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="mi">21</span><span class="p">)</span>
<span class="n">test_eq</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">splits</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span> <span class="mi">17</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">splits</span> <span class="o">=</span> <span class="n">get_splits</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">100</span><span class="p">),</span> <span class="n">valid_size</span><span class="o">=</span><span class="mf">0.213</span><span class="p">,</span> <span class="n">test_size</span><span class="o">=</span><span class="mi">17</span><span class="p">,</span> <span class="n">train_size</span><span class="o">=</span><span class="mf">.2</span><span class="p">)</span>
<span class="n">splits</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_png output_subarea ">
<img src="
"
>
</div>

</div>

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>((#12) [3,89,71,40,37,34,96,90,42,47...],
 (#21) [33,92,73,21,72,97,38,27,1,6...],
 (#17) [67,31,10,79,56,12,74,66,2,41...])</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="get_predefined_splits" class="doc_header"><code>get_predefined_splits</code><a href="https://github.com/timeseriesAI/tsai/tree/main/tsai/data/validation.py#L290" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>get_predefined_splits</code>(<strong>*<code>xs</code></strong>)</p>
</blockquote>
<p>xs is a list with X_train, X_valid, ...</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="combine_split_data" class="doc_header"><code>combine_split_data</code><a href="https://github.com/timeseriesAI/tsai/tree/main/tsai/data/validation.py#L299" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>combine_split_data</code>(<strong><code>xs</code></strong>, <strong><code>ys</code></strong>=<em><code>None</code></em>)</p>
</blockquote>
<p>xs is a list with X_train, X_valid, .... ys is None or a list with y_train, y_valid, ....</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h4 id="get_splits_len" class="doc_header"><code>get_splits_len</code><a href="https://github.com/timeseriesAI/tsai/tree/main/tsai/data/validation.py#L307" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>get_splits_len</code>(<strong><code>splits</code></strong>)</p>
</blockquote>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">X_train</span><span class="p">,</span> <span class="n">y_train</span><span class="p">,</span> <span class="n">X_valid</span><span class="p">,</span> <span class="n">y_valid</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">splits</span> <span class="o">=</span> <span class="n">combine_split_data</span><span class="p">([</span><span class="n">X_train</span><span class="p">,</span> <span class="n">X_valid</span><span class="p">],</span> <span class="p">[</span><span class="n">y_train</span><span class="p">,</span> <span class="n">y_valid</span><span class="p">])</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">X</span><span class="p">[</span><span class="n">splits</span><span class="p">[</span><span class="mi">0</span><span class="p">]])</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">X_valid</span><span class="p">,</span> <span class="n">X</span><span class="p">[</span><span class="n">splits</span><span class="p">[</span><span class="mi">1</span><span class="p">]])</span>
<span class="n">test_type</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">X</span><span class="p">)</span>
<span class="n">test_type</span><span class="p">(</span><span class="n">y_train</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">X_train</span><span class="p">,</span> <span class="n">y_train</span><span class="p">,</span> <span class="n">X_valid</span><span class="p">,</span> <span class="n">y_valid</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="mi">4</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">splits</span> <span class="o">=</span> <span class="n">combine_split_data</span><span class="p">([</span><span class="n">X_train</span><span class="p">,</span> <span class="n">X_valid</span><span class="p">],</span> <span class="p">[</span><span class="n">y_train</span><span class="p">,</span> <span class="n">y_valid</span><span class="p">])</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">X_train</span><span class="p">[:,</span> <span class="kc">None</span><span class="p">],</span> <span class="n">X</span><span class="p">[</span><span class="n">splits</span><span class="p">[</span><span class="mi">0</span><span class="p">]])</span>
<span class="n">test_eq</span><span class="p">(</span><span class="n">X_valid</span><span class="p">[:,</span> <span class="kc">None</span><span class="p">],</span> <span class="n">X</span><span class="p">[</span><span class="n">splits</span><span class="p">[</span><span class="mi">1</span><span class="p">]])</span>
<span class="n">test_type</span><span class="p">(</span><span class="n">X_train</span><span class="p">,</span> <span class="n">X</span><span class="p">)</span>
<span class="n">test_type</span><span class="p">(</span><span class="n">y_train</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

</div>
 

